<template>
	<view>
		<view class="address" v-for="(res, index) in siteList" v-if="islogin==true">
			<view class="address_name">
				<text style="width: 30%;">{{ res.name }}</text>
				<text>{{ res.mobile }}</text>
			</view>
			<view class="address_add">
				<text v-if="res.is_default==1" class="addres_defult">默认</text>
				<!-- 
				<text v-if="res.tag==0" class="addres_defult" style="background-color:#007AFF">家</text>
				<text v-if="res.tag==1" class="addres_defult" style="background-color:#007AFF">公司</text>
				<text v-if="res.tag==2" class="addres_defult" style="background-color:#007AFF">学校</text> -->
				<text class="addres_addinfo">{{res.region}}{{res.address}}</text>
			</view>
			<view class="address_line"></view>
			<view class="addres_bottom">
				<view>
					<checkbox-group @change="Choose">
						<label>
							<checkbox value="r1" :checked="checked" :disabled="radiochec" color="#1B223E" />
							<text>设为默认地址</text>
						</label>
					</checkbox-group>
				</view>

				<view>
					<image src="../../../static/Mine/ee.png" @tap="editaddres(res.id)"></image>
					<image src="../../../static/Mine/fill.png" @tap="deladdres(res.id)"></image>
				</view>
			</view>
		</view>
		<view class="address" v-if="islogin==false">
			<view class="address_name">
				<text style="width: 30%;">赵先生</text>
				<text>13212345678</text>
			</view>
			<view class="address_add">
				<text class="addres_defult">默认</text>
				<text class="addres_addinfo">广东省 深圳市 宝安区 前海湾 前海湾 前海湾</text>
			</view>
			<view class="address_line"></view>
			<view class="addres_bottom">
				<view>
					<checkbox-group @change="Choose">
						<label>
							<checkbox value="r1" :checked="checked" color="#1B223E" /><text>设为默认地址</text>
						</label>
					</checkbox-group>
				</view>

				<view>
					<image src="../../../static/Mine/ee.png" @tap="editaddres(res.id)"></image>
					<image src="../../../static/Mine/fill.png" @tap="deladdres(res.id)"></image>
				</view>
			</view>
		</view>
		<view class="address_footer">
			<view class="left">从微信导入</view>
			<view class="right" @click="toAddSite">新增地址</view>
		</view>
	</view>

</template>
<script>
	import {
		addresslist,
		addressedel
	} from '@/api/mine.js'
	export default {
		data() {
			return {
				checked: false,
				siteList: [],
				islogin: false,
				siteList2: [],
				cart_ids: "",
				coupon_id: "",
			};
		},
		onLoad(point) {
			this.cart_ids = point.ids
			this.coupon_id = point.couponId
			this.getaddlist()
		},
		onShow() {
			this.getaddlist()
		},
		methods: {
			Choose(){
				
			},
			// 获取地址列表
			getaddlist() {
				addresslist().then(res => {
					console.log(res)
					this.siteList = res.data.list
					this.islogin = true
				})
			},
			// 删除地址
			deladdres(id) {
				addressedel({
					id: id
				}).then(res => {
					console.log(res)
					if (res.status == 200) {
						uni.showToast({
							title: '删除成功',
							duration: 2000,
						})
					}
				})
			},
			editaddres(id) {
				uni.navigateTo({
					url: '../address/addsite2?type=1&id=' + id,
					fail(fail) {
						console.log(fail)
					}
				});
			},
			toAddSite() {
				uni.navigateTo({
					url: '../address/addsite2',
					fail(fail) {
						console.log(fail)
					}
				});
			},
			//选择地址
			choiceAddress(res) {
				console.log(res)
				uni.navigateTo({
					url: "/pages/orderPay/payment2?ids=" + this.cart_ids + "&&addressId=" + res.id +
						"&&couponId=" + this.coupon_id
				})
			}
		}
	}
</script>
<style lang="scss" scoped>
	page {
		background-color: #F7F8F9;
	}

	.address {
		color: #FFF;
		// position: relative;
		background-color: #FFF;
		border-radius: 15rpx;
		padding: 10rpx;
		margin: 20rpx;
		height: 250rpx;
	}

	.address_name {
		display: flex;
		justify-content: flex-start;
		align-items: left;
		font-size: 36rpx;
		font-weight: 500;
		color: #171E3A;
		padding: 10rpx 30rpx;
	}

	.address_add {
		color: #333;
		padding: 10rpx 30rpx;
		display: flex;
		// justify-content: space-between;
	}

	.addres_defult {
		color: #FFF;
		width: 10%;
		background-color: #FF4891;
		padding: 10rpx;
		border-radius: 10rpx;
		font-size: 18rpx;
		text-align: center;
	}

	.addres_addinfo {
		color: #59585F;
		font-weight: bold;
		font-size: 26rpx;
		margin-left: 10rpx;
	}

	.addres_bottom {
		display: flex;
		margin-top: 20rpx;
		font-size: 28rpx;
		justify-content: space-between;
		color: #59585F;
		padding: 10rpx 30rpx;

		image {
			background-image: url(../../../static/Mine/bg.png);
			background-size: 60rpx 60rpx;
			padding: 5rpx;
			width: 40rpx;
			height: 40rpx;
			margin-left: 20rpx;
			border-radius: 20rpx;
		}
	}

	.address_footer {
		width: 100%;
		height: 90rpx;
		background: #FFFFFF;
		position: absolute;
		display: flex;
		justify-content: center;
		align-items: center;
		bottom: 30rpx;
		z-index: 999;
		padding: 10rpx 0rpx;
	}

	.left {
		width: 43%;
		color: #fff;
		text-align: center;
		line-height: 80rpx;
		height: 80rpx;
		background: linear-gradient(127deg, #283156 0%, #171E3A 100%);
		border-radius: 44rpx 0rpx 0rpx 44rpx;
	}

	.right {
		width: 43%;
		color: #fff;
		text-align: center;
		line-height: 80rpx;
		height: 80rpx;
		background: linear-gradient(135deg, #FF78AE 0%, #FF4891 100%);
		border-radius: 0rpx 44rpx 44rpx 0rpx;
	}

	.address_line {
		margin-top: 20rpx;
		width: 100%;
		height: 1rpx;
		background-color: #F5F5F5;
	}
</style>
